import Vue from "vue";
import VueRouter from "vue-router";
import { asyncRouterMap } from "./routers";

Vue.use(VueRouter);
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};
const baseRouters = [
  {
    path: "*",
    redirect: "/login",
    fullPath: "/login",
  },
  {
    path: "/login",
    name: "login",
    fullPath: "/login",
    component: () => import("../pages/index/views/login/index.vue"),
  },
];
baseRouters.push(...asyncRouterMap);

const router = new VueRouter({
  mode: "history",
  base: `${process.env.VUE_APP_ROUTER_BASE}/`,
  routes: baseRouters,
  scrollBehavior: () => ({ y: 0 }),
});

export default router;
